package com.lyf.work1;

import java.util.Scanner;

public class Random {
    public static void main(String[] args) {


        //方法一:Math.random()  【0,1)的随机小数
        int num=(int)(Math.random()*100)+1;
        guess(num);
        System.out.println("正确随机数是：" + num);
        //方法二：导包Random
        // Random r = new Random();
        //int num=r.nextInt(100)+1;
    }
        public static void guess(int r) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个数字：");
            int LuckNumber=sc.nextInt();
            while (true) {

                if (LuckNumber==r) {
                    System.out.println("恭喜你猜对了！");
                    break;
                } else if (LuckNumber>r) {
                    System.out.println("你猜的数字太大了！");
                    System.out.println("请重新输入一个数字：");
                    LuckNumber=sc.nextInt();
                } else if (LuckNumber<r) {
                    System.out.println("你猜的数字太小了！");
                    System.out.println("请重新输入一个数字：");
                    LuckNumber=sc.nextInt();
                }

            }

    }
}
